import jwt
from jwt import ExpiredSignatureError, InvalidTokenError
SECRET_KEY = "djangobase+vue"
def decode_jwt(token):
    try:
        # 解码 token，自动验证过期时间和签名
        decoded_payload = jwt.decode(token, SECRET_KEY, algorithms=["HS256"])
        username = decoded_payload.get("username")
        return username
    except ExpiredSignatureError:
        print("Token has expired.")
        return None
    except InvalidTokenError:
        print("Invalid token.")
        return None
